package com.wego.controller.admin;

import com.wego.bean.PageBean;
import com.wego.bean.ResultBean;
import com.wego.converter.StrategyConverter;
import com.wego.domain.dto.StrategyDTO;
import com.wego.domain.entity.Strategy;
import com.wego.domain.query.StrategyQuery;
import com.wego.domain.vo.StrategyVO;
import com.wego.service.StrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章(tb_strategy)表控制层
 *
 */
@RestController
@RequestMapping("/admin/strategy")
public class AdminStrategyController {
    @Autowired
    private StrategyService strategyService;
    @Autowired
    private StrategyConverter strategyConverter;
    
    @GetMapping("/{id}")
    public ResultBean<StrategyVO> getWithNames(@PathVariable Integer id) {
        // 使用修改后的方法，返回带作者名和游戏名的数据
        final StrategyVO strategyVO = strategyService.getPageWithNamesById(id);
        return ResultBean.success(strategyVO);
    }
    
    @GetMapping("/page")
    public ResultBean<PageBean<StrategyVO>> page(StrategyQuery strategyQuery) {
        // 使用修改后的方法，返回带作者名和游戏名的数据
        final PageBean<StrategyVO> pageBean = strategyService.getPageWithNames(strategyQuery);
        return ResultBean.success(pageBean);
    }

    @PutMapping
    public ResultBean<Void> update(@RequestBody StrategyDTO strategyDTO) {
        final Strategy strategy = strategyConverter.dto2entity(strategyDTO);
        strategyService.update(strategy);
        return ResultBean.success("修改成功!", null);
    }

    @PostMapping
    public ResultBean<Void> insert(@RequestBody StrategyDTO strategyDTO) {
        final Strategy strategy = strategyConverter.dto2entity(strategyDTO);
        strategyService.insert(strategy);
        return ResultBean.success("添加成功!", null);
    }
    @DeleteMapping
    public ResultBean<Void> batchDelete(@RequestParam List<Integer> ids) {
        strategyService.deleteByIds(ids);
        return ResultBean.success("批量删除成功!", null);
    }

}
